package org.zw.store.admin.api;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.zw.store.admin.dao.MealDao;
import org.zw.store.admin.dto.MealDto;
import org.zw.store.admin.model.Meal;
import org.zw.store.common.Result;

import java.util.Date;
import java.util.List;

@Slf4j//方便日志输出
@Transactional//事务注解
@RestController
@RequestMapping("/admin/meal")
public class MealApi {

    @Autowired
    private MealDao mealDao;

    @GetMapping
    public Result<List<Meal>> mealList(){
        List<Meal> mealList = mealDao.findMealList();
        return Result.OK(mealList);
    }

    @PostMapping
    public Result mealSave(@RequestBody MealDto mealDto){
        mealDto.setInsert_time(new Date());
        mealDao.insertMeal(mealDto);
        return Result.OK();
    }
}
